import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.Scanner;
import java.util.Vector;

public class CallTheRoll {
    static Scanner sc = new Scanner(System.in);
    public CallTheRoll(Vector<Student> a) throws Exception {
        System.out.print("是否开始点名?输入1点名，其他退出系统：");
        if (sc.next().equals("1")) {
            for (Student m : a) {
                dian(m);
            }
        } else {
            System.out.println("退出点名");
        }
        sc.close();
        System.out.println("签到结束");

        //点名结束全部重置为2
        Connection connection = DBUtil.getConnection();
        String sql = "update student set state = 2";
        PreparedStatement ps = connection.prepareStatement(sql);
        ps.executeUpdate();
    }

    public void dian(Student m) throws Exception {
        new TestToSpeech(m.name).read();
        System.out.print(m.name + "到了吗？: ");
        if (m.state == false) {
            System.out.println(m.name + "已请假" + "");
            return;
        }
        m.state = (sc.nextInt() == 1) ? true : false;
        System.out.print(m.id + " " + m.name + "：" + ((m.state) ? "已签到" : "签到失败") + "\n");
    }
}
